package java_thread;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * 线程让步例子
 *
 */
public class demo_20_yield {
    public static void main(String[] args){
        Thread_yield t1 = new Thread_yield("t1");
        Thread_yield t2 = new Thread_yield("t2");
        t1.start();
        t2.start();
    }
}

class Thread_yield extends Thread{
    public Thread_yield(String name){
        super(name);
    }
    public synchronized void run(){
        for(int i=0; i <10; i++){
            System.out.printf("%s [%d]:%d\n", this.getName(), this.getPriority(), i);
            // i整除4时，调用yield
            if (i%4 == 0)
                Thread.yield();
        }
    }
}